package com.sky.mapper;

import com.sky.dto.GoodsSalesDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;

@Mapper
public interface ReportMapper {

    /**
     * 根据日期获取总金额
     * @param date
     * @return
     */
    @Select("select sum(amount) from orders where status = 5 and DATE(order_time) = #{date}")
    BigDecimal getAmountByDate(LocalDate date);

    /**
     * 获取用户总数
     * @param date
     * @return
     */
    @Select("select count(id) from user where DATE(create_time) <= #{date}")
    Long getTotalUserByDate(LocalDate date);

    /**
     * 获取新用户数量
     * @param date
     * @return
     */
    @Select("select count(id) from user where DATE(create_time) = #{date}")
    Long getNewUserCountByDate(LocalDate date);

    @Select("select count(id) from orders where DATE(order_time) = #{date} and status = 5")
    Long getCompletedOrderByDate(LocalDate date);

    @Select("select count(id) from orders where DATE(order_time) = #{date}")
    Long getOrderByDate(LocalDate date);

    @Select("select od.name,sum(od.number) as number from order_detail od,orders o where DATE(o.order_time) >= #{begin}" +
            " and DATE(order_time) <= #{end} and o.id = od.order_id group by od.name order by number DESC")
    List<GoodsSalesDTO> getGoodSales(LocalDate begin, LocalDate end);
}
